<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListCargoTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">     

            <p:growl id="messages" life="3000" />

            <h:panelGroup id="messagePanel" styleClass="ajustaListaMensagemErro"  layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="list"/>
            </h:panelGroup>

            <h:panelGroup >

                <p:dataTable id="tbl" value="#{cargoController.lista}" var="item"  paginator="true" rows="#{bundle.rows}" pageLinks="5" widgetVar="cargoTable"
                             currentPageReportTemplate="#{bundle.currentPageReportTemplateCargo}"  paginatorTemplate="#{bundle.paginatorTemplate}"
                             rowsPerPageTemplate="#{bundle.rowsPerPageTemplate}"  paginatorPosition="#{bundle.paginatorPosition}" emptyMessage="#{bundle.ListCargoEmpty}" rowKey="#{item.crgId}" selection="#{cargoController.selectedCargo}" selectionMode="single">


                    <f:facet id="global" name="header">
                        <p:outputPanel id="test" >
                            <h:outputText value="#{bundle.searchAllFields}" />
                            <p:inputText id="globalFilter" onkeyup="cargoTable.filter();" style="width: 200px;" >
                                <p:focus for="globalFilter" />
                            </p:inputText>
                        </p:outputPanel>
                    </f:facet>

                    <p:column styleClass="firstColumn" filterBy="#{item.crgId}" sortBy="#{item.crgId}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListCargoTitle_crgId}"/>
                        </f:facet>
                        <h:outputText value="#{item.crgId}"/>
                    </p:column>
                    <p:column filterBy="#{item.crgNm}" sortBy="#{item.crgNm}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListCargoTitle_crgNm}"/>
                        </f:facet>
                        <h:outputText value="#{item.crgNm}"/>
                    </p:column>
                    <p:column filterBy="#{item.crgDesc}" sortBy="#{item.crgDesc}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListCargoTitle_crgDesc}"/>
                        </f:facet>
                        <h:outputText value="#{item.crgDesc}"/>
                    </p:column>

                    <p:column style="width:3%" exportable="false">
                        <div class="cabecalho">
                            <div class="imagem">
                                <p:commandLink update=":formList:displayView" oncomplete="cargoDialogView.show()" onerror="cargoDialogView.hide();" title="#{bundle.MsgVisualizar}" styleClass="ui-icon ui-icon-search">
                                    <f:setPropertyActionListener value="#{item}" 
                                                                 target="#{cargoController.selectedCargo}" />
                                    
                                </p:commandLink>
                            </div>                 
                            <div class="titulo">
                                <p:commandLink ajax="false"  action="#{cargoController.prepareEdit}" rendered="#{!autenticadorController.loginVisualizador}" title="#{bundle.ListAreaEditLink}" styleClass="ui-icon ui-icon-pencil" >
                                    <f:setPropertyActionListener value="#{item}" 
                                                                 target="#{cargoController.selectedCargo}" />
                                </p:commandLink>
                            </div>
                        </div>                     
                    </p:column>

                    <f:facet name="footer">
                        <p:commandButton id="createCommand" rendered="#{!autenticadorController.loginVisualizador}" ajax="false" icon="ui-icon-document" action="#{cargoController.prepareCreate}" value="#{bundle.ListCargoCreateLink}"/>
                        <p:commandButton id="viewCommand"  value="#{bundle.MsgVisualizar}" icon="ui-icon-search"  update=":formList:displayView" oncomplete="cargoDialogView.show();" actionListener="#{cargoController.prepareView}" />
                        <p:commandButton id="editCommand" ajax="false" action="#{cargoController.prepareEdit}" value="#{bundle.ListCargoEditLink}" icon="ui-icon-pencil" />
                        <p:commandButton id="deleteCommand" ajax="false" rendered="#{autenticadorController.loginAdmin}" onclick="confirmationDestroy.show();" value="#{bundle.ListCargoDestroyLink}" type="button" icon="ui-icon-trash" />

                        <p:commandButton id="excelExportAll" ajax="false" value="#{bundle.excelExportAll}" icon="ui-icon-script">
                            <p:dataExporter type="xls" target="tbl" fileName="#{bundle.excelExportAllFileName_Cargo}" postProcessor="#{cargoController.postProcessorXLS}"/>
                        </p:commandButton>
                        <p:commandButton id="excelExportPagAtual" ajax="false" value="#{bundle.excelExportPagAtual}" icon="ui-icon-calculator">
                            <p:dataExporter type="xls" target="tbl" fileName="#{bundle.excelExportPagAtualFileName_Cargo}" pageOnly="true" postProcessor="#{cargoController.postProcessorXLS}"/>
                        </p:commandButton>
                    </f:facet>
                </p:dataTable>
                <p:confirmDialog id="confirmDestroy" message="#{bundle.MsgConfirmDestroy_message}" header="#{bundle.MsgConfirmDestroy_header}" severity="alert" widgetVar="confirmationDestroy">
                    <p:commandButton id="confirm" ajax="false" value="#{bundle.MsgDialog_confirmar}"  oncomplete="confirmationDestroy.hide(); #{cargoController.prepareList}" action="#{cargoController.destroy}" update="tbl"/>
                    <p:commandButton id="decline"  value="#{bundle.MsgDialog_cancelar}" update="messages" onclick="confirmationDestroy.hide();" type="button"/>

                </p:confirmDialog>

                <p:dialog id="dialogView" header="#{bundle.CargoDialogView_header}" widgetVar="cargoDialogView" resizable="false" modal="true"
                          width="500" >

                    <h:panelGrid id="displayView" columns="2" cellpadding="4">                          

                        <h:outputText value="#{bundle.ViewCargoLabel_crgId}"/>
                        <h:outputText value="#{cargoController.selected.crgId}" title="#{bundle.ViewCargoTitle_crgId}"/>
                        <h:outputText value="#{bundle.ViewCargoLabel_crgNm}"/>
                        <h:outputText value="#{cargoController.selected.crgNm}" title="#{bundle.ViewCargoTitle_crgNm}"/>
                        <h:outputText value="#{bundle.ViewCargoLabel_crgDesc}"/>
                        <h:outputText value="#{cargoController.selected.crgDesc}" title="#{bundle.ViewCargoTitle_crgDesc}"/>  

                        <h:outputLabel value="#{bundle.createBy}" for="nomeCriador" rendered="#{not empty cargoController.selected.historicoCriacao.nomeUsuario}"/>
                        <h:outputText id="nomeCriador" value="#{cargoController.selected.historicoCriacao.nomeUsuario}" rendered="#{not empty cargoController.selected.historicoCriacao.nomeUsuario}"/>
                        <h:outputLabel value="#{bundle.createDate}" for="dataCriacao" rendered="#{not empty cargoController.selected.historicoCriacao.dataHora}"/>
                        <h:outputText id="dataCriacao" value="#{cargoController.selected.historicoCriacao.dataHora}" rendered="#{not empty cargoController.selected.historicoCriacao.dataHora}"/>     
                        <h:outputLabel value="#{bundle.updateBy}" for="nomeAlterador" rendered="#{not empty cargoController.selected.historicoAlteracao.nomeUsuario}"/>
                        <h:outputText id="nomeAlterador" value="#{cargoController.selected.historicoAlteracao.nomeUsuario}" rendered="#{not empty cargoController.selected.historicoAlteracao.nomeUsuario}"/>
                        <h:outputLabel value="#{bundle.updateDate}" for="dataAlteracao" rendered="#{not empty cargoController.selected.historicoAlteracao.dataHora}"/>
                        <h:outputText id="dataAlteracao" value="#{cargoController.selected.historicoAlteracao.dataHora}" rendered="#{not empty cargoController.selected.historicoAlteracao.dataHora}" /> 

                    </h:panelGrid>
                </p:dialog>
            </h:panelGroup>

            <!--</h:form>--> 
        </ui:define>
    </ui:composition>

</html>
